<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=path %>/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript">
	var spanId = "";
	function ajaxsub(goodsId)
	{
		 var str="";
         jQuery("input[name='cates"+goodsId+"']:checked").each(function(){
             str += (str==""?"":",") + $(this).val();
             spanId += (spanId==""?"":",") + ($(this).val()+"span"+goodsId);
            
         });
       
         jQuery("input[name='cates"+goodsId+"']:checkbox").each(function(){
           if(!$(this).attr("checked"))
           {
        	   $("#"+($(this).val()+"span"+goodsId)).css("background","");
           }
            
         });         
          $.ajax({
        	   type: "POST",
        	   url: "<%=path%>/label.do?method=ajaxEditProfile",
        	   data: "data="+str+"&goodsId="+goodsId,
        	   success: function(msg){
        		   backfun();
        		   spanId = "";
        	   }
        });
 	}
	function backfun()
	{
		var strs = spanId.split(",");
		for(var s = 0;s<strs.length;s++)
		{
			$("#"+strs[s]).css("background","red");
			
		}
		
	}
	
	function onpage()
	{
		var currpage = $("#currpage").val() - 1;
		if(currpage<=0)
		{
			$("#currpage").val(1);
			alert("当前已经第一页!");
			return;
		}else{
			$("#currpage").val(currpage);
			window.document.getElementById("frm").submit();
		}
		
		
	}
	function nextpage()
	{
		var currpage = parseInt($("#currpage").val()) + 1;
		var totalpage = $("#totalPage").val();
		if(currpage>totalpage)
		{
			alert("当前已经是最后一页!");
			return;
		}else{
			$("#currpage").val(currpage);
			window.document.getElementById("frm").submit();
		}
		
		
	}
	function changeType()
	{
		$("#currpage").val(1);
	}
	function toPage()
	{
		var topage = $("#topage").val();
		var totalpage = $("#totalPage").val();
		if(isNaN(topage))
		{
			alert("请填入数字!");
			return;
		}
		var pg = parseInt(topage);
		if(pg <=0 )
		{
			alert("页码不能小于1");
			return;
		}
		if(pg > totalpage)
		{
			alert("您输入的数字已超过总页数!");
			return;
		}
		$("#currpage").val(pg);
		window.document.getElementById("frm").submit();
		
	}
	
	function toPage2()
	{
		var topage = $("#topage2").val();
		var totalpage = $("#totalPage").val();
		if(isNaN(topage))
		{
			alert("请填入数字!");
			return;
		}
		var pg = parseInt(topage);
		if(pg <=0 )
		{
			alert("页码不能小于1");
			return;
		}
		if(pg > totalpage)
		{
			alert("您输入的数字已超过总页数!");
			return;
		}
		$("#currpage").val(pg);
		window.document.getElementById("frm").submit();
		
	}
	
	</script>


</head>
<body>
<form action="<%=path %>/label.do?method=initPageList" id="frm" name="frm" method="post">
<input type="hidden" id="currpage" name = "currpage" value="${currpage}"/>
<input type="hidden" id="totalPage" name = "totalPage" value="${totalPage}"/>

<input type="hidden" value="100" name="count" />
	<table align="center" width="90%" border="1">
		<tr>
			<td align="left" width="40%">
				<select name="categoryType" onchange="changeType();">
				<option value="-1" ${-1 == categoryType?'selected':'' }>全部</option>
				<option value="-2" ${-2 == categoryType?'selected':'' }>未标注</option>
					<c:forEach items="${categoryList }" var="cate">
						<option value="${cate.goodsCategoryId }" ${categoryType ==cate.goodsCategoryId?'selected':'' }>${ cate.goodsCategoryNameZh}</option>
					</c:forEach>
				</select>
				
			</td>
			<td align="left" width="60%"><input type="submit" value="搜索" />&nbsp;&nbsp;&nbsp;<a href="javascript:onpage();" style="TEXT-DECORATION:none">上一页</a>&nbsp;&nbsp;&nbsp;<a href="javascript:nextpage();" style="TEXT-DECORATION:none">下一页</a>&nbsp;&nbsp;&nbsp;<input type="text" value="${currpage }" size="5" id="topage" name="topage"><input type="button" value="to" onclick="toPage();" size="10">&nbsp;&nbsp;&nbsp;<span style="margin-right: 15px;">记录数:${ goodsprofileTotal} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共 ${totalPage }页 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;每页条${count }记录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前第${currpage }页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
		</tr>
		<tr>
			<td width="100%" colspan="2">
				<table width="100%" border="1">
					<c:forEach items="${goodsprofile }" var="goods">
					<tr>
						<td width="25%">${goods.title}</br></br>startTime:${goods.startTime }</br> endTime:${goods.endTime }</br><h4>${goods.goodsId }<h4></td>
						<td width="75%">
							<table width="100%">
								<tr>
									<td align="left" width="45%">
									<c:forEach items="${categoryList }" var="cate" varStatus="status" begin="0" end="8">
										<c:forEach items="${goods.categorys }" var="oldcategory">
											<c:if test="${oldcategory == cate.goodsCategoryId }">
												<c:set var="check" value="checked"></c:set>
												<c:set var="rowcolor" value="red"></c:set>
											</c:if>
										</c:forEach>
										<input type="checkbox" name="cates${goods.goodsId }" ${check} onclick="javascript:ajaxsub(${goods.goodsId });"  value="${cate.goodsCategoryId }"/><span id="${cate.goodsCategoryId}span${goods.goodsId }"  style="background:${rowcolor};">${ cate.goodsCategoryNameZh}</span><br>
										<c:set var="check" value=""></c:set>
										<c:set var="rowcolor" value=""></c:set>
									</c:forEach>
									</td>
									
									<td align="left">
										<c:forEach items="${categoryList }" var="cate" varStatus="status" begin="9">
											<c:forEach items="${goods.categorys }" var="oldcategory">
												<c:if test="${oldcategory == cate.goodsCategoryId }">
													<c:set var="check" value="checked"></c:set>
													<c:set var="rowcolor" value="red"></c:set>
												</c:if>
											</c:forEach>
											<input type="checkbox" name="cates${goods.goodsId }"  ${check} onclick="javascript:ajaxsub(${goods.goodsId });" value="${cate.goodsCategoryId }"/><span id="${cate.goodsCategoryId}span${goods.goodsId }"  style="background:${rowcolor};">${ cate.goodsCategoryNameZh}</span><br>
											<c:set var="check" value=""></c:set>
											<c:set var="rowcolor" value=""></c:set>
										</c:forEach>
									</td>
								</tr>
								<!--<tr>
									<td colspan="2" align="center">
										<table width="100%" border="1">
											<tr>
												<td><input type="button" value="保存" onclick="ajaxsub(${goods.goodsId });"/> </td>
											</tr>
										</table>
									</td>
								</tr>
							--></table>
						</td>
					</tr>
					</c:forEach>
				</table>
			</td>
		</tr>
		
		
		<tr>
			<td align="left" width="50%">
				<select name="categoryType"  onchange="changeType();">
				<option value="-1" ${-1 == categoryType?'selected':'' }>全部</option>
				<option value="-2" ${-2 == categoryType?'selected':'' }>未标注</option>
					<c:forEach items="${categoryList }" var="cate">
						<option value="${cate.goodsCategoryId }" ${categoryType ==cate.goodsCategoryId?'selected':'' }>${ cate.goodsCategoryNameZh}</option>
					</c:forEach>
				</select>
				
			</td>
			<td align="left" width="50%"><input type="submit" value="搜索" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:onpage();" style="TEXT-DECORATION:none">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:nextpage();" style="TEXT-DECORATION:none">下一页</a>&nbsp;&nbsp;&nbsp;<input type="text" value="${currpage }" size="5" id="topage2" name="topage2"><input type="button" value="to" onclick="toPage2();" size="10"> <span style="margin-right: 15px;">记录数:${ goodsprofileTotal} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共 ${totalPage }页 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;每页条${count }记录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前第${currpage }页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
		</tr>
	</table>
	
	</form>
</body>
</html>